package fr.enseirb.mycub.structures;

import java.util.ArrayList;

import android.database.Cursor;
import android.provider.BaseColumns;

import com.google.android.maps.GeoPoint;

import fr.enseirb.mycub.db.InternetDBConstants;
import fr.enseirb.mycub.db.InternetDBConstants;

public class Internet extends Station {
	private String mAddress;
	private boolean free;

	public static final String ADDRESS = "address";
	public static final String FREE = "free";
	
	public Internet() {
		super();
	}

	public void setAddress(String address) {
		mAddress = address;
	}

	public String getAddress() {
		return mAddress;
	}

	public boolean isFree() {
		return free;
	}

	public void setFree(boolean free) {
		this.free = free;
	}
	
	public static ArrayList<Internet> getInternetFromCursor(Cursor cursor){

		ArrayList<Internet> items = new ArrayList<Internet>();

		if(cursor.getCount() == 0 ) return items;

		//------- Internet table -------

		int latitudeColumn = cursor
				.getColumnIndex(InternetDBConstants.KEY_LATITUDE);
		int longitudeColumn = cursor
				.getColumnIndex(InternetDBConstants.KEY_LONGITUDE);
		int freeColumn = cursor
				.getColumnIndex(InternetDBConstants.KEY_FREE);
		int idColumn = cursor
				.getColumnIndex(BaseColumns._ID);

		cursor.moveToFirst();
		Internet l = null;

		int size = cursor.getCount();
		for(int i =  0; i < size; i ++){
			l = new Internet();
			l.mId = cursor.getInt(idColumn);
			int lat = cursor.getInt(latitudeColumn);
			int lon = cursor.getInt(longitudeColumn);
			l.mGeoPoint = new GeoPoint(lat,lon);
			l.free = cursor.getInt(freeColumn) == 1 ? true : false;
		items.add(l);
		cursor.moveToNext();
	}

	cursor.close();

	return items;
}

}